package at.playbox.server.businesslogic;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBService
{
	private String dbUrl = null;
	private String dbUser = null;
	private String dbPasswd = null;
	private String query = null;
	private Connection conn = null;
	private Statement statement = null;
	private ResultSet rs = null;

	public DBService(String dbUser, String dbPasswd)
	{
		this.dbUrl = "jdbc:mysql://localhost:3306/playbox";
		this.dbUser = dbUser;
		this.dbPasswd = dbPasswd;
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
			// Setup the connection with the DB
			this.conn = DriverManager.getConnection(getDbUrl(), getDbUser(), getDbPasswd());
		}
		catch (Exception e)
		{
			System.out.println("Treiber konnte nicht geladen werden!");
		}
	}

	public ResultSet executeStatement(String query)
	{
		try
		{
			// Statements allow to issue SQL queries to the database
			this.statement = this.conn.createStatement();
			// Result set get the result of the SQL query
			this.rs = statement.executeQuery(query);
			rs.close();
			return rs;
		}
		catch (Exception e)
		{
			return null;
		}
	}

	public boolean deletStatement(String query)
	{
		return true;
	}

	public String getDbUrl()
	{
		return dbUrl;
	}

	public void setDbUrl(String dbUrl)
	{
		this.dbUrl = dbUrl;
	}

	public String getDbUser()
	{
		return dbUser;
	}

	public void setDbUser(String dbUser)
	{
		this.dbUser = dbUser;
	}

	public String getDbPasswd()
	{
		return dbPasswd;
	}

	public void setDbPasswd(String dbPasswd)
	{
		this.dbPasswd = dbPasswd;
	}

	public String getQuery()
	{
		return query;
	}

	public void setQuery(String query)
	{
		this.query = query;
	}

	public Connection getConn()
	{
		return conn;
	}

	public void setConn(Connection conn)
	{
		this.conn = conn;
	}

}
